//
//  ReplayCellView.m
//  兼职页面
//
//  Created by kuiyuan liang on 2021/5/30.
//

#import "ReplayCellView.h"
#import "CommonUtil.h"
#import "ReplayViewController.h"

@interface ReplayCellView()
@property (strong, nonatomic) UIImageView * iconImageView;
@property (strong, nonatomic) UILabel * nameLabel;

@property (strong, nonatomic) UILabel * replayLabel;
@property (strong, nonatomic) UIImageView * replayIconImageView;
@property (strong, nonatomic) UILabel * replayNameLabel;
@property (strong, nonatomic) UILabel * replayContentLabel;

@property (strong, nonatomic) UIButton * replayBtn;
@property (strong, nonatomic) UIButton * reportBtn;
@end

@implementation ReplayCellView

-(instancetype)init{
    if (self = [super init]) {
        
        self.clipsToBounds = YES;
        [self addSubview:self.iconImageView];
        [self addSubview:self.nameLabel];
        
        [self addSubview:self.replayLabel];
        [self addSubview:self.replayIconImageView];
        [self addSubview:self.replayNameLabel];
        [self addSubview:self.replayContentLabel];
        
        
        [self addSubview:self.reportBtn];
        [self addSubview:self.replayBtn];

    }
    return self;
}



-(void)setModel:(MessageModel *)model{
    _model = model;
    self.iconImageView.frame = CGRectMake(AD(20),AD(5) , AD(20), AD(20));
    self.nameLabel.frame = CGRectMake(self.iconImageView.right + AD(7), 0, AD(100), AD(30));
    self.replayLabel.frame = CGRectMake(AD(20), _nameLabel.bottom, AD(30), AD(15));
    self.replayIconImageView.frame = CGRectMake(_replayLabel.right,_replayLabel.top , AD(20), AD(20));
    self.nameLabel.text = model.replayName;
    self.replayContentLabel.text = model.replayContent;
    
    if (model.replayYourSelf) {
        self.replayNameLabel.text = @"";
        self.replayNameLabel.frame = CGRectMake(_replayIconImageView.right + AD(3), _replayLabel.top, 0, AD(15));
    }else{
        self.replayNameLabel.text = model.replayOtherName;
        CGFloat contentW = [CommonUtil countWidth:model.replayOtherName font:self.replayNameLabel.font height:AD(15)];
        self.replayNameLabel.frame = CGRectMake(_replayIconImageView.right + AD(3), _replayLabel.top, contentW, AD(15));
    }
    
    
    CGFloat contentW = self.width - self.replayNameLabel.right;
    CGFloat contentH = [CommonUtil countHeight:self.replayContentLabel.text font:self.replayContentLabel.font width:contentW];
    self.replayContentLabel.frame = CGRectMake(_replayNameLabel.right, _replayLabel.top, contentW, contentH);
    self.replayNameLabel.centerY = self.replayLabel.centerY;
    self.replayContentLabel.left = self.replayNameLabel.right;
    
    
    if (model.isDetail) {
        self.replayBtn.hidden = false;
        self.reportBtn.hidden = false;
        self.replayBtn.centerY = self.nameLabel.centerY;
        self.reportBtn.centerY = self.nameLabel.centerY;
    }else{
        self.replayBtn.hidden = YES;
        self.reportBtn.hidden = YES;
    }
//    self.replayContentLabel.backgroundColor = [UIColor redColor];
//    self.replayLabel.backgroundColor = [UIColor redColor];
//    self.replayNameLabel.backgroundColor = [UIColor redColor];
//    self.nameLabel.backgroundColor = [UIColor redColor];
}

- (void)replayBtnClick:(UIButton *)sender{
    NSLog(@"回复");
    [self.superVC presentViewController:[ReplayViewController new] animated:YES completion:nil];
}

- (void)reportBtnClick:(UIButton *)sender{
    NSLog(@"举报");
    BaseAlert *alert = [HudFactory creatHudWithType:@"ReportAlert"];
    [alert show];
}



-(UIImageView *)iconImageView{
    if (!_iconImageView) {
        _iconImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
        _iconImageView.image = [UIImage imageNamed:@"defaultIcon.jpeg"];
        _iconImageView.layer.cornerRadius = AD(10);
        _iconImageView.clipsToBounds = YES;
    }
    return _iconImageView;
}

-(UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        _nameLabel.font = [UIFont systemFontOfSize:AD(17)];
        _nameLabel.textColor = RGB(71.0, 118.0, 158.0);
    }
    return _nameLabel;
}

-(UILabel *)replayLabel{
    if (!_replayLabel) {
        _replayLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        _replayLabel.font = [UIFont systemFontOfSize:AD(13)];
        _replayLabel.textColor = [UIColor blackColor];
        _replayLabel.text = @"回复";
    }
    return _replayLabel;
}

-(UIImageView *)replayIconImageView{
    if (!_replayIconImageView) {
        _replayIconImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
        _replayIconImageView.image = [UIImage imageNamed:@"defaultIcon.jpeg"];
        _replayIconImageView.layer.cornerRadius = AD(10);
        _replayIconImageView.clipsToBounds = YES;
    }
    return _replayIconImageView;
}

-(UILabel *)replayNameLabel{
    if (!_replayNameLabel) {
        _replayNameLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        _replayNameLabel.font = [UIFont systemFontOfSize:AD(13)];
        _replayNameLabel.textColor = RGB(71.0, 118.0, 158.0);
    }
    return _replayNameLabel;
}


-(UILabel *)replayContentLabel{
    if (!_replayContentLabel) {
        _replayContentLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        _replayContentLabel.font = [UIFont systemFontOfSize:AD(14)];
        _replayContentLabel.textColor = [UIColor lightGrayColor];
        _replayContentLabel.numberOfLines = 0;
    }
    return _replayContentLabel;
}



-(UIButton *)replayBtn{
    if (!_replayBtn) {
        _replayBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_replayBtn setTitle:@"回复" forState:UIControlStateNormal];
        [_replayBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _replayBtn.frame = CGRectMake(_reportBtn.right + AD(0), 0, AD(35), AD(15));
        _replayBtn.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
        _replayBtn.layer.cornerRadius = AD(10);
        _replayBtn.clipsToBounds = YES;
        _replayBtn.titleLabel.font = [UIFont systemFontOfSize:AD(11)];
    }
    return _replayBtn;
}

-(UIButton *)reportBtn{
    if (!_reportBtn) {
        _reportBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _reportBtn.frame = CGRectMake(self.width-AD(130), 0, AD(80), AD(15));
        _reportBtn.titleLabel.font = [UIFont systemFontOfSize:AD(11)];
        [_reportBtn setTitle:@"举报" forState:UIControlStateNormal];
        [_reportBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_reportBtn setImage:[UIImage imageNamed:@"icon_warning"] forState:UIControlStateNormal];
        _reportBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -AD(10));
    }
    return _reportBtn;
}

@end
